

namespace Nadine
{
	//----------------------------------------------------
	// NDProfiler
	//----------------------------------------------------
	class NDProfileMgr;
	class NDProfiler :public NDBaseObject
	{
	private:
	protected:
		std::string		m_strProfileName;
		float			m_fCreateTime;
		NDProfileMgr*	m_pProfileMgr;

		virtual void markCreateTime()	=0;
		virtual void uploadInfo()		=0;

	public:
		NDProfiler( NDArk* pArk, std::string strProfileName, NDProfileMgr* pProfileMgr ) :
		  NDBaseObject(99), 
		  m_strProfileName( strProfileName ),
		  m_pProfileMgr( pProfileMgr )
		{
			this->setArk( pArk );
			markCreateTime();
		}

		virtual ~NDProfiler()
		{
			uploadInfo();
			this->m_bReleased =true;
		}

	};


	//----------------------------------------------------
	// NDProfileMgr (NOT thread-safe )
	// needs
	// NDCLOCK
	// NDFONT
	//----------------------------------------------------
	class NDProfileMgr :public NDBaseObject
	{
	private:
		bool	m_bUploadingProfile;
		bool	m_bInitialized;

		bool	m_bEnableProfiler;

		struct sProfileInfo
		{
			std::string strModuleName;
			
			float		fCycleTime;
			float		fTotalTime;

			UINT		nCycleRunTimes;
			UINT		nTotalRunTimes;

			NDUID		nStringID;

		};
		CGrowableArray< sProfileInfo* > m_myProfilePool;


	protected:
		//bool isUploadingProfile() { return m_bUploadingProfile; }
		//void setUploadProfile(bool bUploading);

		void updateString(sProfileInfo* pProfileInfo);


	public:
		NDProfileMgr() :NDBaseObject(10), m_bUploadingProfile(false), m_bInitialized(false), m_bEnableProfiler(false) {}
		virtual ~NDProfileMgr()
		{
			assert( m_myProfilePool.GetSize() ==0);
		}

		virtual bool initialize();
		virtual void release();

		void uploadProfile(std::string strProfileName, float fUsedTime);
		void cleanCycleTime();

		void dumpProfileData( const char* pCharFileName );

		void drawProfileStateString(float fElapsedTime, UINT nPosiX, UINT nPosiY);
		void drawProfileStateFigure(float fElapsedTime, UINT nPosiX, UINT nPosiY, UINT nWidth, UINT nHeight);
		

	};




}